package cn.donting.jme.expansion.builder.light;

import cn.donting.jme.EditorContent;
import cn.donting.jme.editor.scene.Scene;
import cn.donting.jme.editor.scene.wrapper.LightWrapper;
import cn.donting.jme.expansion.attribute.Attribute;
import cn.donting.jme.expansion.attribute.lmpl.ColorAttribute;
import cn.donting.jme.expansion.attribute.lmpl.FloatAttribute;
import cn.donting.jme.expansion.builder.AttributeBuilder;
import cn.donting.jme.ioc.Bean;
import com.jme3.light.Light;

import javax.swing.*;
import java.util.List;

public abstract class LightAttributeBuilder<T extends Light> implements AttributeBuilder<T> {

    public static final int ICON_SIZE = 16;

    public abstract T newInstance();

    public abstract Icon getIcon(int size);
    public abstract Icon getActiveIcon(int size);

    public abstract String getName();

    @Override
    public void attribute(List<Attribute> attributes, T light) {
        Scene scene = EditorContent.getScene();
        LightWrapper wrapper = scene.getWrapper(light, LightWrapper.class);
        ColorAttribute colorAttribute = new ColorAttribute("颜色:");
        colorAttribute.setValue(wrapper.getColor());
        colorAttribute.setValueChangeListener(newValue -> {
            wrapper.setColor(newValue);
            light.setColor(wrapper.toColorRGBA());
        });
        attributes.add(colorAttribute);

        FloatAttribute floatAttribute = new FloatAttribute("强度:");
        floatAttribute.setMinValue(0);
        floatAttribute.setStepSize(0.1f);
        floatAttribute.setValue(wrapper.getIntensity());
        floatAttribute.setValueChangeListener(newValue -> {
            wrapper.setIntensity(newValue);
            light.setColor(wrapper.toColorRGBA());
        });
        attributes.add(floatAttribute);
    }
}
